package cn.iocoder.yudao.module.crm.controller.admin.clue.vo.robotdistributeconfig;

import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;

@Schema(description = "管理后台 - CRM 线索自动分配规则 Response VO")
@Data
public class CrmRobotClueDistributeConfigRespVO {

    @Schema(description = "启用状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
    @NotNull(message = "启用状态")
    private Boolean enabled;

    @Schema(description = "分配类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    @NotNull(message = "分配类型")
    private Integer type;

    @Schema(description = "领取上限", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
    @NotNull(message = "领取上限")
    private Integer limitConfig;

    @Schema(description = "兜底负责人", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
    private Long defaultOwner;

    @Schema(description = "配置列表")
    private List<DistributeConfigVO> configList;

    @Schema(description = "创建时间")
    private LocalDateTime createTime;

    @Schema(description = "所属模块")
    private Long moduleId;



    @Data
    public static class DistributeConfigVO {
        private Long userId;
        private Boolean enable; // 是否开启分配
        private Integer hourCount;
        private Integer dayCount;
        private Integer weekCount;
        private Integer monthCount;
        private Integer totalCount;
    }

    public static class DistributeConfigTypeHandler extends AbstractJsonTypeHandler<Object> {

        @Override
        protected Object parse(String json) {
            return JsonUtils.parseArray(json, DistributeConfigVO.class);
        }

        @Override
        protected String toJson(Object obj) {
            return JsonUtils.toJsonString(obj);
        }

    }
}
